package com.atguigu.gmall.mq.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.mq.config.DeadLetterExchange;
import com.atguigu.gmall.mq.config.DelayedMqConfig;
import com.atguigu.gmall.service.RabbitService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 生产者
 */
@RestController
@RequestMapping("/api/mq")
public class ProducerController {

    /*    @Autowired
        private RabbitTemplate rabbitTemplate;
        //发消息
        @GetMapping("/sendMessage")
        public Result sendMessage(String message){

            rabbitTemplate.convertAndSend("exchange1",
                    "routingKey1","测试一下");

            return Result.ok();
        }*/
    @Autowired
    private RabbitService rabbitService;
    //发消息
    @GetMapping("/sendMessage")
    public Result sendMessage(String message) {
        rabbitService.sendMessage("exchange1",
                "routingKey1","测试一下");
        return Result.ok();
    }
    //基于死信交换机   发延迟消息
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message) {
        rabbitService.sendDelayMessage(DeadLetterExchange.exchange_dead
          ,DeadLetterExchange.routing_dead_1,"延迟消息测试一波","5000");
        return Result.ok();
    }
    //基于插件的 延迟消息
    @GetMapping("/sendDelayMessagePlugins")
    public Result sendDelayMessagePlugins(String message) {
        rabbitService.sendDelayMessagePlugins(DelayedMqConfig.exchange_delay,
                DelayedMqConfig.routing_delay,"插件延迟消息测试一波",6000);
        return Result.ok();
    }
}
